var Aip = "";
var Aback = {"Did":"","bid":""};
var inOpCode = 1;
var Awauth,Awuser;
var Weibo=Object();
var lastpage='';
var Auser = {};
var Auserinfo = {};
var Auth = {};//认证信息
var Aset = {};
var Asl={};
var Achat = {};
var Acqueue = {};
var Arqueue = {};
var Apoll= {};
var myScroll = {};
var Asocket;
var Agl={hostname:'10.0.0.93',ajax_id:100,ajax:{},fid_oid:{},fid_uid:{},uid_fid:{},uid_oid:{},oid_uid:{},oid_fid:{},brcss:"webkit",dialog_num:{}};
var weibo_auth_url = "https://api.weibo.com/oauth2/authorize?client_id=1480042123&redirect_uri=http%3A%2F%2F"+Agl.hostname+"%3A93%2Fweibo-index-auth_call&response_type=code&display=mobile";
jQuery(document).ready(function(){
	var view = false;
	if(Acan.browser.opera){
		view = true;
		Agl.brcss = "o";
		//Acan.includes('app/weibo.opera.css','css');
	}
	if(Acan.browser.webkit) view = true;
	if(!view){
		Acan.alert("你的浏览器暂不支持本应用，请先下载支持的浏览器访问，将来会支持。<br>支持的浏览器：chrome，safari，opera，360极速浏览器5，搜狗浏览器3，QQ浏览器6，遨游3，世界之窗极速版<br>推荐使用谷歌的Chrome浏览器",0,{width:'320px',height:'320px'});
		return;
	}
	Awuser = new Weibo.user('weibo','Awuser');
	Awauth = new Weibo.auth(".-auth","Awauth");
	Weibo.ready();
	Awauth.login_html();
	Awauth.reg_html();
	Awauth.weibo_html();
	Weibo.page("home");
	var ring = '/plugin/Voicemail.mp3';
	jQuery(".-body").append(
	Ahtml.tag("div",{'class':'dis_none'},Ahtml.tag("audio",{'id':"ring_sms",'controls':'controls','src':ring})));
	Weibo.dialog();
	Weibo.chat.recv_daemon();
	Weibo.setsize();
	jQuery(window).resize(function(){Weibo.setsize();});
});
Weibo = function(obj){}
//设置全局变量
Weibo.agl = function(obj){
	if(obj.uid){
		Agl.fid_uid[obj.fid] = obj.uid;
		Agl.uid_fid[obj.uid] = obj.fid;
	}
	if(obj.oid){
		Agl.fid_oid[obj.fid] = obj.oid;
		Agl.oid_fid[obj.oid] = obj.fid;
	}
	if(obj.oid && obj.uid){
		Agl.uid_oid[obj.uid] = obj.oid;
		Agl.oid_uid[obj.oid] = obj.uid;
	}
}
Weibo.socket = function(){
	var url = "ws://"+Agl.hostname+":8893/";
	Asocket = io.connect(url);
	Asocket.on('connect', function () {
		if(Awauth.check('no')) Weibo.auth.set(Auth.uid,1);//当前有登入的自动认证此通信
		Asocket.on('message', function (msg) {
		});
		Asocket.on('error', function (msg) {
		});
		Asocket.on('Achat', function (data) {
			if(data.fid==Auth.fid){Weibo.poll.chat(data,2);}//发送信息回调
			else if(data.tfid==Auth.fid){Achat.recv_queue(data);}//接受信息回调
		});
		Asocket.on('Aajax', function (ajax_id,data) {
			try{
				Agl.ajax[ajax_id].callback(data);//回调函数
				if(Agl.ajax[ajax_id].bg==1) Acan.ajax_bg(0);
				setTimeout(function(){Acan.ajax.load(2);},300);
				delete Agl.ajax[ajax_id];
			}catch(e){};
		});
		Asocket.on('disconnect', function (msg) {
			Weibo.ready.logout();
			//setTimeout(function() {Weibo.socket();}, 500);//断开自动重连
		});
	});
}

//跨域代理请求功能
Weibo.proxy = function(url){
	return url;
	var Aweibourl = "http://"+Acan.url.host()+"/tool-proxy?url=http://fate.nice9s.com:93/";
	return Aweibourl+url;
}
Weibo.setsize = function(){
	var ht = jQuery(window).height();
	if(ht<400){ht=400;}
	jQuery("._page").css("min-height",ht+'px');
	jQuery(".Wbody").css("min-height",ht+'px');
}
Weibo.page = function(name){
	var title = {"home":"美妙人生","dialog":"对话","friend":"我的好友","set":"设置"};
	jQuery("#footer .-menu ._set").removeClass("_act");
	jQuery("#footer .-menu .s_"+name).addClass("_act");
	var login=true;
	if(Acan.base.in_array(name,["dialog","friend"])){
		login = Awauth.check();
	}
	jQuery('title').text(title[name]);
	var head = jQuery("#header");
	head.text(title[name]);
	jQuery("#header ._btn").remove();
	if(name=='home'){
		if(!Awauth.check('no')) head.append(Ahtml.tag('span',{'class':"loginButton_24",'onclick':"Awauth.show('weibo','.Wbody')"}));
	}
	if(name=='friend'){head.append(Weibo.tpl.btnh("添加","Weibo.friend.add()"));}
	jQuery('.Wbody .-main').hide();
	var Did = "weibo_"+name;
	if(jQuery("#"+Did).length==0){
		jQuery(".Wbody #header").after(Ahtml.tag('div',{"id":Did,"class":"-main"},Ahtml.tag('div',{"class":"-scroll"})));
	}
	lastpage = name;
	var main = jQuery("#"+Did);
	main.show();
	if(login){
		setTimeout("Weibo."+name+"(\"Weibo.iscroll('weibo_"+name+"')\")",1);
	}
}
Weibo.home = function(fun){
	var jDid = "#weibo_home";
	var main = jQuery('#weibo_home .-scroll');
	var bhtml = Ahtml.tag('select',{"name":"Y","onchange":"setday('#weibo_home ')"},dateoption("Y",1990))
	+Ahtml.tag('select',{"name":"m","onchange":"setday('#weibo_home ')"},dateoption("m"))
	+Ahtml.tag('select',{"name":"d"},dateoption("d","",1))+" "
	+Ahtml.tag('select',{"name":"h"},dateoption("h"));
	html = Ahtml.tag("li",{},
			Ahtml.tag("div",{"class":"_t"},"生日:")
			+Ahtml.tag("div",{"class":"_d _birthday"},bhtml))
		+Ahtml.tag("li",{},
			Ahtml.tag("div",{"class":"_t"},"方式:")
			+Ahtml.tag("div",{"class":"_d _check"},
				Weibo.tpl.btn_span("生肖"+Acan.icon.right(),"Weibo.home.check('1')",{"class":"_fate","fid":"1"})
				+Weibo.tpl.btn_span("星座","Weibo.home.check('2')",{"class":"_fate","fid":"2"})
			)
		)
		+Ahtml.tag('li',{},Ahtml.tag("p",{"class":"_t"},"性 别:")+Ahtml.tag("p",{"class":"_d _check"},
			Weibo.tpl.btn_span("男","Weibo.sex.check('1','"+jDid+"')",{"class":"_sex","fid":"1"})
			+Weibo.tpl.btn_span("女","Weibo.sex.check('2','"+jDid+"')",{"class":"_sex","fid":"2"})
		))
		+Ahtml.tag("li",{},
			Ahtml.tag("div",{"class":"btn"},Weibo.tpl.sub("配对查询"))
			+Ahtml.tag("div",{"class":"btn"},Weibo.tpl.btn("信息查询","Weibo.home.findinfo()"))
		);
	html = Ahtml.tag("form",{"onsubmit":"Weibo.home.find();return false;"},Ahtml.tag("ol",{"class":"Am_list _login _main_bg"},html));
	main.html(html);
	if(fun){setTimeout(fun,1);}
	if(Awauth.check('no')){
		try{
			var userinfo = Weibo.user.info();
			if(!userinfo){
				Awuser.info(function(data){Weibo.home.autoset(data,jDid);});
			}else{
				Weibo.home.autoset(userinfo,jDid);
			}
		}catch(e){}
	}
}
Weibo.home.autoset = function(userinfo,jDid){
	if(!userinfo.fate.birthday || !userinfo.fate.sex){
		Awuser.wanshan();return;
	}
	var ssex = 1;
	if(userinfo.fate.sex==1){
		ssex=2
	}
	Weibo.sex.check(ssex,jDid);
	jQuery('#weibo_home input[name="sex"]').val(ssex);//如果有账户登入，自动设置性别
	Weibo.check.birthday("#weibo_home",userinfo.fate.birthday);//如果有账户登入，自动设置生日信息
}
//获取配对方式的选项 返回数组
Weibo.home.check_val = function(name){
	Did = "#weibo_home ._fate";
	var frr = [];
	jQuery(Did).each(function(i){
		var fid = jQuery(this).attr("fid");
		if(jQuery(this).find(".-icon_rt").length>0){
			frr.push(fid);
		}
	})
	return frr;
}
//配对查找
Weibo.home.find = function(type){
	if(!type) type=1;
	Awauth.check();
	var frr = Weibo.home.check_val();
	var sex = Weibo.sex.val('#weibo_home');
	var birthday = Weibo.check.birthday("#weibo_home ._birthday");
	if(!birthday){return;}
	var save = {"birthday":birthday,"fid":frr,"sex":sex};
	var url = Aurl.App+'-api-find_fate';
	Weibo.gets(url,save,function(data){
		var Did = ".home_find";
		var head = "配对结果"+Weibo.tpl.btnh("返回","Weibo.set.back('"+Did+"')")+Weibo.tpl.btnh("换一组","Weibo.home.find('2')",'r');
		var html = Weibo.user.list(data.data,"home.find",".home_find");
		Acan.storage.set("home.find",data.data);
		Weibo.tpl.body(Did,"home_find",head,html);
		if(type==1) Weibo.ml(".Wbody",Did);
	});
}
//查询生日信息
Weibo.home.findinfo = function(name){
	var birthday = Weibo.check.birthday("#weibo_home ._birthday");
	if(!birthday){return;}
	var save = {"birthday":birthday};
	var url = Aurl.App+'-api-find_info';
	var data = Weibo.gets(url,save,function(data){
		var Did = ".home_findinfo";
		var head = "生日信息"+Weibo.tpl.btnh("返回","Weibo.set.back('"+Did+"')");
		var html = Weibo.home.info(Did,data.data);
		Weibo.tpl.body(Did,"home_findinfo",head,html);
		Weibo.ml(".Wbody",Did);
	},2);
}
Weibo.home.info = function(Did,obj){
	var html = '';
	var que=Acan.base.obj_str(obj.wuxing.que,2);
	html = Ahtml.tag("ol",{"class":"Am_list _login _main_bg"},
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"生肖:")+Ahtml.tag("p",{"class":"_d"},obj.shengxiao.title))+
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"星座:")+Ahtml.tag("p",{"class":"_d"},obj.xingzuo.title))+
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"公历:")+Ahtml.tag("p",{"class":"_d"},obj.gongli))+
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"农历:")+Ahtml.tag("p",{"class":"_d"},obj.nongli))+
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"八字:")+Ahtml.tag("p",{"class":"_d"},obj.bazi.title))+
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"五行:")+Ahtml.tag("p",{"class":"_d"},obj.wuxing.title))+
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"亏缺:")+Ahtml.tag("p",{"class":"_d"},que))
	);
	return html;
}
Weibo.friend = function(fun){
	var act;
	if(!act) act = 'friend';
	var fdata = Acan.storage.get("fate."+Auth.uid+'.'+act);
	if(fdata && Acan.count(fdata) > 0){
		Weibo.friend.call(fdata,act);
	}else{
		var url = Aurl.App+'-api-'+act;
		var save = {};
		Weibo.gets(url,save,function(data){
			Weibo.friend.call(data.data,act,2);
		});
	}
	if(fun){setTimeout(fun,1);}
}
Weibo.friend.call = function(data,act,type){
	var obj={};
	for(var i in data){
		obj[data[i].fid] = data[i];
	}
	var main = jQuery('#weibo_friend .-scroll');
	if(!type) type=1;
	var Did = ".fate_"+act;
	var html = Weibo.user.list(obj,"fate."+Auth.uid+"."+act,'.Wbody',1);
	main.html(html);
	if(type!=1) Acan.storage.set("fate."+Auth.uid+'.'+act,obj);//更新本地缓存
}
Weibo.friend.add = function(){
	var Did = ".friend_add";
	var head = "添加好友"+Weibo.tpl.btnh("返回","Weibo.set.back('"+Did+"')");
	var html = Ahtml.tag("ol",{"class":"Am_list _login _main_bg"},
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"邮 箱:")+Ahtml.tag("p",{"class":"_d"},
		Ahtml.tag("input",{"type":"email","name":"mail","placeholder":"对方的邮箱地址","size":18})))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"btn"},Weibo.tpl.sub("查找")))
	)
	html = Ahtml.tag("form",{"onsubmit":"Weibo.user.find();return false;","class":"_main -center"},html);
	Weibo.tpl.body(Did,"friend_add",head,html);
	Weibo.ml(".Wbody",Did);
}
//选择配对方式
Weibo.home.check = function(name){
	Did = "#weibo_home ._fate[fid=\""+name+"\"]";
	var val = jQuery(Did).find(".-icon_rt").length;
	if(val==1){
		jQuery(Did).find(".-icon_rt").remove();
	}else{
		jQuery(Did).append(Acan.icon.right());
	}
}
Weibo.dialog = function(fun){
	var main = jQuery('#weibo_dialog .-scroll');
	var html = Weibo.dialog.list();
	var tatol = 0;
	main.html(html);
	for(var fid in Agl.dialog_num){
		tatol += Agl.dialog_num[fid];
	}
	jQuery(".-menu .m_fate .dialog_num").remove();
	if(tatol>0){
		jQuery(".-menu .m_fate").append(Ahtml.tag('span',{"class":"dialog_num"},tatol));
	}
	if(fun){setTimeout(fun,1);}
}
Weibo.dialog.list = function(){
	var dialog = Acan.storage.get('fate.'+Auth.uid+'.dialog');
	var chatdata = Acan.storage.get("Achatdata."+Auth.fid);
	if(typeof dialog!="object" || typeof chatdata!="object"){return '';}
	var html='';
	for(var fid in dialog){
		dialog[fid].fid=fid;
		Weibo.agl(dialog[fid]);
		if(typeof chatdata[fid]!='object'){delete dialog[fid];continue;}
		Agl.dialog_num[fid]=0;
		for(var nid in chatdata[fid]){
			if(nid=='indexs') continue;
			if(chatdata[fid][nid].path==2 && chatdata[fid][nid].status==1){
				Agl.dialog_num[fid]++;
			}
		}
		var id = chatdata[fid].indexs[Acan.count(chatdata[fid].indexs)-1];//最后一条记录的nid
		html += Weibo.dialog.list_li(dialog[fid],chatdata[fid][id]);
	}
	Acan.storage.set('fate.'+Auth.uid+'.dialog',dialog);
	return Ahtml.tag("ul",{"class":"Am_list user_list _main_bg"},html);
}
Weibo.dialog.list_li = function(ubj,lastobj){
	var html='',num='';
	if(Agl.dialog_num[ubj.fid]>0) num = Ahtml.tag('span',{"class":"dialog_num"},Agl.dialog_num[ubj.fid]);
	var click = "Weibo.user.list_chat("+ubj.fid+",'fate."+Auth.uid+".dialog')";
	html = Ahtml.tag('div',{"class":"_avatar"},Ahtml.tag('img',{"src":Weibo.avatar(ubj.oid)})+num)
	+Ahtml.tag('div',{"class":"_info","onclick":click},
		Ahtml.tag("div",{"class":"title"},ubj.username)
		+Ahtml.tag("div",{"class":"note"},Acan.time("Y-m-d H:i:s",lastobj.time))
		+Ahtml.tag("div",{"class":"fate"},lastobj.note)
	)
	return Ahtml.tag("li",{onclick:click},html);
}
Weibo.dialog.save = function(obj){
	var dialog = Acan.storage.get('fate.'+Auth.uid+'.dialog');
	if(!dialog){dialog = {};}
	if(!dialog[obj.fid]){dialog[obj.fid] = obj;}
	Acan.storage.set('fate.'+Auth.uid+'.dialog',dialog);
}
Weibo.check = function(){}
Weibo.check.birthday = function(Did,birthday){
	if(!Did){return false;}
	var Yobj = jQuery(Did+' input[name="Y"]');
	if(Yobj.length==0){
		Yobj = jQuery(Did+' select[name="Y"]');
	}
	var mobj = jQuery(Did+' select[name="m"]');
	var dobj = jQuery(Did+' select[name="d"]');
	var hobj = jQuery(Did+' select[name="h"]');
	if(birthday){
		var brr = birthday.substr(0,13).replace(" ",'-').split('-');
		var bdate = new Date(brr[0],brr[1],brr[2],brr[3]);
		Yobj.val(bdate.getFullYear());
		var month = bdate.getMonth();if(month<10){month = "0"+month;}
		mobj.val(month);
		var day = bdate.getDate();if(day<10){day = "0"+day;}
		dobj.val(day);
		var hours = bdate.getHours();if(hours<10){hours = "0"+hours;}
		hobj.val(hours);
		return birthday;
	}
	var myDate = new Date();
	var year = Acan.base.str_int(Yobj.val());
	//限制年份在1950-当前年内
	if(Acan.base.is_numeric(Yobj.val()) && year>1950 && year<(myDate.getFullYear())){
	}else{Yobj.focus();return false;}
	if(mobj.val().length==0){mobj.focus();return false;}
	if(dobj.val().length==0){dobj.focus();return false;}
	if(hobj.val().length==0){hobj.focus();return false;}
	var birthday = Yobj.val()+"-"+mobj.val()+"-"+dobj.val()+" "+hobj.val()+":00:00";
	return birthday;
}
Weibo.set = function(fun){
	var main = jQuery('#weibo_set .-scroll');
	var html = '';
	html = Ahtml.tag("li",{"onclick":"Weibo.set.account()"},Ahtml.tag("div",{"class":"_info"},"<b>帐号设置</b>")+Ahtml.tag("div",{"class":"_other"},Acan.icon.arrow("r")))
		+Ahtml.tag("li",{},Ahtml.tag("div",{"class":"_info"},"<b>动画效果</b>")+Acan.icon.onoff("Weibo.set.val('slide','\val')","Weibo.set.val('slide','\val')",Aset.slide.val))
		+Ahtml.tag("li",{"onclick":"Weibo.set.about('')"},Ahtml.tag("div",{"class":"_info"},"<b>关于Myfate</b>")+Ahtml.tag("div",{"class":"_other"},Acan.icon.arrow("r")));
	html = Ahtml.tag("ul",{"class":"Am_list _main_bg"},html)
		+"<br>"
		+Ahtml.tag("ul",{"class":"Am_list _main_bg"},Ahtml.tag("li",{"class":"_one -white -center _bglogout","onclick":"Weibo.auth.logout()"},"<b>退出当前帐号</b>"));
	main.html(html);
	if(fun){setTimeout(fun,1);}
}
//初始化设置信息
Weibo.set.ready = function(){
	Aset = Acan.storage.get("Aset");
	if(!Aset){
		Aset = {"slide":{"title":"滑动效果","val":"1"}};
		Acan.storage.set("Aset",Aset);
	}
}
//设置值
Weibo.set.val = function(key,val){
	if(val != Aset[key].val){
		Aset[key].val = val;
		Acan.storage.set("Aset",Aset);
	}else{
		return false
	}
	return true;
}
Weibo.set.back = function(Did,oDid){
	if(!oDid){oDid=".Wbody";}
	if(Did=='.weibo_chat' && jQuery("#weibo_dialog").css("display")=='block'){
		Weibo.dialog();
	}
	Weibo.mr(oDid,Did);
}
//帐号管理
Weibo.set.account = function(){
	var Did = ".-set_account";
	var Dbj = jQuery(Did);
	var save = Acan.storage.get("user_login");
	if(Dbj.length==0){jQuery(".-body").append(Ahtml.tag("div",{"class":"-set_account dis_none"}));Dbj = jQuery(Did);}
	var head = "帐号管理"+Weibo.tpl.btnh("返回","Weibo.set.back('"+Did+"')")+Weibo.tpl.btnh("编辑","Weibo.set.account_edit()",'r');
	var html = '',mail='',one='';
	if(Acan.count(save.list)==1){
		one = '_one';
	}
	for(var uid in save.list){
		var rt='';
		if(uid==Auth.uid){
			rt = Acan.icon.right();
		}
		mail = save.list[uid].mail;
		html += Ahtml.tag("li",{"class":one,"onclick":"Weibo.auth.set('"+uid+"')","id":"_"+uid},Ahtml.tag('div',{"class":"_info"},"<b>"+mail+"</b>")+Ahtml.tag('div',{"class":"_other"},rt))
	}
	html = Ahtml.tag("ul",{"class":"Am_list _main_bg"},html);
	html += "<br>"+Ahtml.tag("ul",{"class":"Am_list _main_bg"},
		Ahtml.tag("li",{"class":"_one","onclick":"Awauth.show('login','"+Did+"')"},"<b>添加账户</b>")
	);
	Weibo.tpl.body(Did,"set_account",head,html);
	Weibo.ml(".Wbody",Did);
}
//帐号切换后显示设置
Weibo.set.account_set = function(uid){
	jQuery(".-set_account li .-icon_rt").remove();//移除已选
	jQuery(".-set_account #_"+uid+" ._other").append(Acan.icon.right());//选择当前账户
}
Weibo.set.account_edit = function(){

}
Weibo.set.about = function(){
	var Did = "weibo_about";
	var jDid = ".weibo_about";
	var head = "关于Myfate"+Weibo.tpl.btnh("返回","Weibo.set.back('"+jDid+"')");
	var url = "blog.nice9s.com";
	var html = Ahtml.tag("ol",{"class":"Am_list _main_bg"},
		Ahtml.tag('li',{},Ahtml.tag('p',{"class":"_t"},"邮箱:")+Ahtml.tag('p',{"class":"_d"},"abans@qq.com"))
		+Ahtml.tag('li',{},Ahtml.tag('p',{"class":"_t"},"官网:")+Ahtml.tag('p',{"class":"_d"},Ahtml.tag('a',{},url)))
	)
	Weibo.tpl.body(jDid,Did,head,html);
	Weibo.ml(".Wbody",jDid);
}
Weibo.auth = function(Did,objname){
	if(!Did){Did=".-auth";}
	this.Did = Did;
	this.objname = objname;
	jQuery(this.Did).hide();
}
Weibo.auth.prototype = new Weibo.auth();
//登入检测
Weibo.auth.prototype.check = function(type,backDid){
	if(!backDid){backDid='.Wbody';}
	if(!type){type="login";}
	var login = false;
	try{
		if(Auth.uid && Auth.hash && (Acan.time()-Auth.time) < 86400*30){login = true;}
	}catch(e){}
	//检测微博登入
	if(login && type=='weibo' && ((typeof(Auth.oid)=="undefined" || Auth.oid<1) || (typeof(Auth.weibo)=="undefined" || Auth.weibo!=1))){
		login = false;
	}
	if(!login){
		if(type == "login"){setTimeout(this.objname+".show('login','"+backDid+"')",1);}
		if(type == "weibo"){setTimeout(this.objname+".show('weibo','"+backDid+"')",1);}
	}
	return login;
}
//界面切换
Weibo.auth.prototype.show = function(name,Did1){
	var Did;
	if(name=="login"){
		Did = this.Did+"_"+name;
		if(Did1){
			Awauth.login_html(Did1,2);
			Weibo.ml(Did1,this.Did+"_"+name);
		}else{
			Awauth.login_html();
			Weibo.ml(".Wbody",this.Did+"_"+name);
		}
	}else if(name=="reg"){
		Did = this.Did+"_"+name;
		Weibo.ml(this.Did+"_login",this.Did+"_"+name);
	}else if(name=="weibo"){
		Did = this.Did+"_"+name;
		jQuery(this.Did+"_weibo iframe").attr("src",weibo_auth_url);
		if(Did1){
			jQuery(".-auth_weibo .-nav ._btn_hl").attr("onclick","Awauth.back('weibo','"+Did1+"')");
			Weibo.ml(Did1,this.Did+"_"+name);
		}else{
			jQuery(".-auth_weibo .-nav ._btn_hl").attr("onclick","Awauth.back('weibo')");
			Weibo.ml(this.Did+"_login",this.Did+"_"+name);
		}
	}
	setTimeout(function(){
		Weibo.iscroll("Auth_"+name);
	},1)
}
//返回界面切换
Weibo.auth.prototype.back = function(name,backDid){
	if(!backDid){backDid=".Wbody";}
	if(Acan.base.in_array(name,['weibo','reg'])){
		if(backDid){
			Weibo.mr(backDid,this.Did+"_"+name);
		}else{
			Weibo.mr(this.Did+"_login",this.Did+"_"+name);
		}
	}else if(name==1){
		Weibo.mr(backDid,this.Did);
	}else{
		Weibo.mr(backDid,this.Did);
		//Weibo.page("home");//返回主页
	}
}
//注册界面
Weibo.auth.prototype.reg_html = function(){
	var head = "注册"+Weibo.tpl.btnh("返回",this.objname+".back('reg')");
	var bhtml = Ahtml.tag('input',{"name":"Y","onchange":"setday('"+this.Did+" ')","style":"margin:0 0 0 5%;width:auto;","size":4,"placeholder":"1990"},'年')
		+Ahtml.tag('select',{"name":"m","onchange":"setday('"+this.Did+" ')"},dateoption("m"))
		+Ahtml.tag('select',{"name":"d","style":"margin-left:5%;"},dateoption("d","",1))+" "
		+Ahtml.tag('select',{"name":"h"},dateoption("h"));
	html = Ahtml.tag("ol",{"class":"Am_list _login _main_bg"},
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"邮 箱:")+Ahtml.tag("p",{"class":"_d"},Ahtml.tag("input",{"type":"email","name":"mail","placeholder":"请输入您的邮箱地址","size":18})))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"密 码:")+Ahtml.tag("p",{"class":"_d"},Ahtml.tag("input",{"type":"password","name":"pass","placeholder":"6位以上密码","size":18})))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"生 日:")+Ahtml.tag("p",{"class":"_d _birthday"},bhtml))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"性 别:")+Ahtml.tag("p",{"class":"_d _check"},
			Weibo.tpl.btn_span("男","Weibo.sex.check('1','#Auth_reg')",{"class":"_sex","fid":"1"})
			+Weibo.tpl.btn_span("女","Weibo.sex.check('2','#Auth_reg')",{"class":"_sex","fid":"2"})
		))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"地 区:")+Ahtml.tag("div",{"class":"_d"},Ahtml.tag("div",{"class":"_save_area"})))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"btn"},Weibo.tpl.sub("注册"))
		+Ahtml.tag("p",{"class":"btn"},Weibo.tpl.btn("返回",this.objname+".back('reg')")))
	);
	html = Ahtml.tag("form",{"onsubmit":this.objname+".reg();return false;","class":"_main -center"},html);
	Weibo.tpl.body(this.Did+"_reg","Auth_reg",head,html);
	Asl.reg = new Apps.sl(this.Did+"_reg ._save_area",'Asl.reg');
	Asl.reg.readys({1:{'name':'sheng'},2:{'name':'shi'},3:{'name':'xian'}},Acan.area);
}
//登入界面
Weibo.auth.prototype.login_html = function(backDid,md){
	var name = "login",hash="";
	if(!md){md=1;}
	var save={"mail":"","pass":""};
	if(md==1){save = Weibo.auth.login_get();}
	if(save.hash){
		hash = Ahtml.tag("input",{"type":"hidden","name":"Autho"});
		save.pass = save.hash.substr(0,save.num);
	}
	var head = "登入"+Weibo.tpl.btnh("返回",this.objname+".back('"+name+"','"+backDid+"')");
	//var imgsrc = 'http://timg.sjs.sinajs.cn/t4/appstyle/widget/images/loginButton/loginButton_48.png';
	var imgsrc = '/images/weibo/loginButton_48.png';
	var html = Ahtml.tag("ol",{"class":"Am_list _login _main_bg"},
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"邮 箱:")+Ahtml.tag("p",{"class":"_d"},Ahtml.tag("input",{"type":"email","name":"mail","value":save.mail,"placeholder":"请输入您的邮箱地址","size":18})))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"密 码:")+Ahtml.tag("p",{"class":"_d"},Ahtml.tag("input",{"type":"password","name":"pass","value":save.pass,"size":18})+hash))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"btn"},Weibo.tpl.sub("登入"))
		+Ahtml.tag("p",{"class":"btn"},Weibo.tpl.btn("注册",this.objname+".show('reg')")))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"-w100"},"忘记密码？"))
		)
	html += "<br>"+Ahtml.tag("div",{"class":"_login_ot _main_bg"},Ahtml.tag("img",{"onclick":this.objname+".show('weibo')","src":imgsrc}));
	html = Ahtml.tag("form",{"onsubmit":this.objname+".login();return false;","class":"_main -center"},html);
	Weibo.tpl.body(this.Did+"_login","Auth_login",head,html);
	//jQuery(this.Did+"_login").html(head+html);
	jQuery(this.Did+'_login input[name="Autho"]').val(Acan.base.obj_json(save));
}
//微博登入界面
Weibo.auth.prototype.weibo_html = function(name){
	var name = "weibo";
	var head = "微博登入"+Weibo.tpl.btnh("返回",this.objname+".back('"+name+"')");
	var html = Ahtml.tag('iframe',{"class":"a_windows_iframe _main","src":"","frameborder":"0"});
	//jQuery(this.Did+"_weibo").html(head+html);
	Weibo.tpl.body(this.Did+"_weibo","Auth_weibo",head,html);
}
//微博帐号登入回调
Weibo.auth.prototype.weibo_call = function(obj){
	Auth = obj.Auth;
	Acan.storage.set("Auth",Auth);//保存认证信息到本地
	Weibo.auth.login_set({mail:Auth.mail,pass:'123456'});
	Acan.alert("登入成功",1000);
	Weibo.auth.set(Auth.uid,1);
	Aback.bid = jQuery('.-auth_login ._btn_hl').attr('onclick').replace("Awauth.back('login','",'').replace("')",'');
	setTimeout(this.objname+".back('weibo','"+Aback.bid+"')",1);
}
//登入
Weibo.auth.prototype.login = function(obj,type){
	var objname = this.objname;
	var save = {"Auth":Auth};
	if(!obj){
		var uobj = jQuery(this.Did+' input[name="mail"]');
		var pobj = jQuery(this.Did+' input[name="pass"]');
		var aobj = jQuery(this.Did+' input[name="Autho"]');
		if(aobj.length>0){save.Autho = Acan.base.json_obj(aobj.val());}
		save.mail = uobj.val();
		save.pass = pobj.val();
		if(!Acan.regexp.mail.test(save.mail)){
			uobj.focus();
			return; Acan.alert("请输入正确的账户!",1000);
		}
		if(save.pass.length==0){
			pobj.focus();
			return; Acan.alert("请输入密码!",1000);
		}
	}else{
		save = obj;
	}
	url = Aurl.App+"-login";
	var atime = 1000;
	var data = Weibo.gets(url,save,function(data){
		if(typeof(data)=='object'){
			if(data.status==1){//登入成功
				Auser = data.data;
				Auth = data.data.Auth;
				Weibo.agl(Auth);
				Acan.storage.set("Auth",Auth);//保存认证信息到本地
				Weibo.auth.login_set(save);
				Weibo.ready.login();
				if(type==1){return false;}
				if(!obj){
					setTimeout(objname+'.back()',atime);
				}else{
					Acan.alert("切换帐号成功",atime);
					return;
				}
			}else{
				if(type==1){return false;}
				if(!obj){
					if(data.status==2){uobj.focus();}
					if(data.status==3){pobj.focus();}
				}
				atime = 1200;
			}
			if(type==1){return false;}
			Acan.alert(decodeURI(data.msg),atime);
		}
		return false;
	},2);
}
//退出登入
Weibo.auth.logout = function(){
	Auser = {};
	Weibo.ready.logout();
	Weibo.dialog();
	Auth = {"ip":Aip};
	Acan.storage.set("Auth",Auth);
	Acan.alert("退出成功",1000);
	return true;
}
//多帐号切换
Weibo.auth.set = function(uid,type){
	if(!uid){return false;}
	if(!type){type=2;}
	var user_login = Acan.storage.get("user_login");
	if(typeof user_login!='object') return;
	if(Auth.uid == uid && type!=1){return true;}//已经是当前用户
	Weibo.ready.logout();
	ubj = user_login.list[uid];
	var save = {"mail":ubj.mail,"pass":ubj.hash.substr(0,ubj.num),"Autho":ubj};
	Awauth.login(save,type);
	Weibo.set.account_set(uid);
}
//登入成功添加本地用户数据储存
Weibo.auth.login_set = function(save){
	var user_login = Acan.storage.get("user_login");
	if(!user_login){
		user_login = {"last":"","list":{}};
	}
	user_login.last=Auth.uid;
	Auth.mail = save.mail;
	Auth.num = save.pass.length;
	user_login.list[Auth.uid]=Auth;
	Acan.storage.set("user_login",user_login);
}
//本地用户数据读取
Weibo.auth.login_get = function(){
	var user_login = Acan.storage.get("user_login");
	var save = {"mail":"","pass":""};
	var uid;
	if(user_login && user_login.last>0){
		uid = user_login.last;
	}else{return save;}
	if(user_login.list[uid]){
		save=user_login.list[uid];
	}
	return save;
}
//注册
Weibo.auth.prototype.reg = function(){
	var objname = this.objname;
	var save = {"Auth":Auth};
	var uobj = jQuery('#Auth_reg input[name="mail"]');
	var pobj = jQuery('#Auth_reg input[name="pass"]');
	if(!Acan.regexp.mail.test(uobj.val())){uobj.focus();return;}
	if(pobj.val().length==0){pobj.focus();return;}
	var birthday = Weibo.check.birthday(this.Did);
	if(!birthday){return;}
	save.user = {"mail":uobj.val(),"password":pobj.val()};
	save.fate = {"birthday":birthday};
	save.sex = Weibo.sex.val();
	url = Aurl.App+"-api-reg";
	var atime = 1000;
	var data = Weibo.gets(url,save,function(data){
		if(typeof(data)=='object'){
			if(data.data.status==1){//注册成功
				Auth = data.Auth;//认证信息
				Acan.storage.set("Auth",Auth);//保存认证信息到本地
				Weibo.auth.login_set({"mail":save.user.mail,"pass":save.user.password});//保存登入信息到本地
				setTimeout(objname+'.back()',atime);
			}else{
				atime = 1200;
			}
			Acan.alert(decodeURI(data.data.msg),atime);
		}
		return false;
	},2);
}
//从本地读取数据
Weibo.cachelocal = function(){
	var area = Acan.storage.get("Acan.area");
	if(typeof(area)=="object"){
		Acan.area = area;
	}else{
		if(typeof(Acan.area)=="object"){
			Acan.storage.set("Acan.area",Acan.area);
		}else{
			Acan.include("data/area31.js");
			setTimeout("Weibo.cachelocal()",100);
		}
	}
	return;
}
//页面载入
Weibo.ready = function(){
	Weibo.set.ready();
	Auth = Acan.storage.get("Auth");//认证信息
	if(!Auth){Auth = {"ip":Aip};}
	auser = Acan.storage.get("Auser");
	if(typeof auser=="object"){
		Auser = auser;
	}
	//Weibo.cachelocal();
	Achat = new Weibo.chat("weibo_chat","Achat");
	Achat.ready();
	Weibo.socket();
	Weibo.poll.ready();
	if(typeof Awi!='object') Weibo.ready.wfinfo();
}
//登入后的初始化
Weibo.ready.login = function(){
	Agl.recv_status=true;
	Weibo.dialog();
}
//断开连接要做的事
Weibo.ready.logout = function(){
	Arqueue={};
	Agl.recv_status=false;
	jQuery(".weibo_chat .chat_main").html('');
}
Weibo.ready.wfinfo = function(){
	var wfinfo = Acan.storage.get("Awi");
	if(typeof(wfinfo) == "object" && Acan.count(wfinfo)>0){
		Awi = wfinfo;
	}else{
		var url = Aurl.Amodr+'-wfinfo';
		Weibo.gets(url,{},function(data){
			Awi = data;
			Acan.storage.set("Awi",Awi);
		},2);
	}
}

//--客户管理
Weibo.user = function(Did,objname){
	this.Did = Did;
	this.objname = objname;
}
Weibo.user.list = function(obj,cname,backDid,type){
	if(typeof obj!="object"){return '';}
	var html='';
	var info = Weibo.user.info();
	for(var i in obj){
		if(type==1){Weibo.agl(obj[i]);}
		html += Weibo.user.list_li(i,obj[i],info,cname,backDid,type);
	}
	return Ahtml.tag("ul",{"class":"Am_list user_list _main_bg"},html);
}
Weibo.user.list_li = function(n,obj,info,cname,backDid,type){
	if(!type) type=2;//type=1,为好友列表直接聊天;2,为查找列表
	if(typeof obj!="object"){return '';}
	var html='',shengxiao='',xingzuo='',click,click1,click2;
	click1 = "Weibo.user.list_chat("+n+",'"+cname+"','"+backDid+"')";
	click2 = "Weibo.user.list_one("+n+",'"+cname+"','"+backDid+"')";
	if(type==1){click = click1;}else{click = click2;}
	var ifate = info.fate;
	var note = {};
	if(obj.zodiac) shengxiao = Ahtml.tag("a",{}," 生肖:"+Awi.zodiac[obj.zodiac]);
	if(obj.xingzuo) xingzuo = Ahtml.tag("a",{}," 星座:"+Awi.xingzuo[obj.xingzuo]);
	if(Awi.sxfate[ifate.zodiac][obj.zodiac]==1)
		note.sx = "吉";
	else if(Awi.sxfate[ifate.zodiac][obj.zodiac]==2)
		note.sx = "凶";
	else
		note.sx = "平";
	if(ifate.sex==1){
		note.xz = Awi.xzfate[ifate.xingzuo+"_"+obj.xingzuo];
	}else{
		note.xz = Awi.xzfate[obj.xingzuo+"_"+ifate.xingzuo];
	}
	html = Ahtml.tag('div',{"class":"_avatar"},Ahtml.tag('img',{"onclick":click2,"src":Weibo.avatar(obj.oid)}))
		+Ahtml.tag('div',{"class":"_info","onclick":click},
			Ahtml.tag("div",{"class":"title"},obj.username)
			+Ahtml.tag("div",{"class":"note"},shengxiao+" 吉利:"+note.sx)
			+Ahtml.tag("div",{"class":"fate"},xingzuo+" 指数:"+note.xz)
		)
		+Ahtml.tag('div',{"class":"_other"},Acan.icon.arrow("r"));
	return Ahtml.tag("li",{},html);
}
Weibo.user.list_one = function(n,cname,backDid){
	var obj = Acan.storage.get(cname)[n];
	var Did = "home_find_one",fhtml='',jDid = '.'+Did,note = {};
	var head = "详细资料"+Weibo.tpl.btnh("返回","Weibo.set.back('"+jDid+"','"+backDid+"')");
	var info = Weibo.user.info();
	var ifate = info.fate;
	if(obj.zodiac) shengxiao = Ahtml.tag("a",{}," 生肖:"+Awi.zodiac[obj.zodiac]);
	if(obj.xingzuo) xingzuo = Ahtml.tag("a",{}," 星座:"+Awi.xingzuo[obj.xingzuo]);
	if(Awi.sxfate[ifate.zodiac][obj.zodiac]==1)
		note.sx = "吉";
	else if(Awi.sxfate[ifate.zodiac][obj.zodiac]==2)
		note.sx = "凶";
	else
		note.sx = "平";
	if(ifate.sex==1){
		note.xz = Awi.xzfate[ifate.xingzuo+"_"+obj.xingzuo];
	}else{
		note.xz = Awi.xzfate[obj.xingzuo+"_"+ifate.xingzuo];
	}
	var html = Ahtml.tag("ol",{"class":"Am_list user_list _main_bg"},
			Ahtml.tag('li',{},Ahtml.tag('div',{"class":"_avatar"},
			Ahtml.tag('img',{"src":Weibo.avatar(obj.oid),"onclick":"Weibo.img_show('"+Weibo.avatar(obj.oid,'max')+"')"}))
			+Ahtml.tag("div",{"class":"title"},obj.username))
		)
	html += "<br>"+Ahtml.tag("ol",{"class":"Am_list _main_bg"},
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"all"},"基本信息"))+
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"生肖:")+Ahtml.tag("p",{"class":"_d"},Awi.zodiac[obj.zodiac]))+
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"星座:")+Ahtml.tag("p",{"class":"_d"},Awi.xingzuo[obj.xingzuo]))+
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"地区:")+Ahtml.tag("p",{"class":"_d"},get_area_val(obj)))
	);
	if(!Agl.fid_oid[obj.fid]) fhtml = Ahtml.tag("p",{"class":"btn"},Weibo.tpl.btn_span("加为好友","Weibo.user.add_friend("+n+",'"+cname+"','home_find_one')"));
	html += "<br>"+Ahtml.tag("ol",{"class":"Am_list _main_bg"},
		Ahtml.tag("li",{},Ahtml.tag("p",{"class":"all"},"缘分信息"))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"生肖吉利:")+Ahtml.tag("p",{"class":"_d"},note.sx))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"_t"},"星座指数:")+Ahtml.tag("p",{"class":"_d"},note.xz))
		+Ahtml.tag("li",{},Ahtml.tag("p",{"class":"btn"},Weibo.tpl.btn_span("悄悄话","Weibo.user.list_chat("+n+",'"+cname+"','home_find_one')"))+fhtml)
	);
	html = Ahtml.tag("div",{"class":"user_one"},html);
	Weibo.tpl.body(jDid,Did,head,html);
	Weibo.ml(backDid,jDid);
	/*
	用户相册
	var url = Aurl.App+'-api-users_photos';
	var save = {"oid":obj.oid};
	var data = Weibo.gets(url,save,function(data){
		Acan.alert(data);
	},1,{'load':2,'bg':2});*/
}
Weibo.user.list_chat = function(n,cname,backDid){
	if(!backDid) backDid='.Wbody';
	var obj = Acan.storage.get(cname)[n];
	Achat.show(obj,backDid);
}
//查找好友
Weibo.user.find = function(){
	var mobj = jQuery(".friend_add input[name=\"mail\"]");
	var mail = mobj.val();
	if(mail.length<1){mobj.focus();return;}
	var url = Aurl.App+'-api-user_find';
	Weibo.gets(url,{'mail':mail},function(data){
		var cname = 'home.find';
		var obj = data.data;
		if(typeof obj=='object' && obj.fid>0){
			Acan.storage.set(cname,{0:obj});
			Weibo.user.list_one(0,cname,'.friend_add');
		}else{
			Acan.alert('你查找的邮箱还未开通本应用，是否推荐他开通？');
		}
	});
}
//加为好友
Weibo.user.add_friend = function(n,cname,backDid){
	var obj = Acan.storage.get(cname)[n];
	if(!Awauth.check("",'.'+backDid)){return;}
	var save = {"fid":obj.fid};
	var url = Aurl.App+'-api-add_friend';
	var data = Weibo.gets(url,save,function(data){
		Acan.alert(data.data.msg,1000);
		var cname = "fate."+Auth.uid+'.friend';
		var fdata = Acan.storage.get(cname);
		fdata[obj.fid] = obj;
		Acan.storage.set(cname,fdata);//更新本地缓存
		Weibo.agl(obj);
	},1,{"backid":backDid,"bg":2});
}
Weibo.user.prototype = new Weibo.user();
Weibo.user.prototype.show = function(title,html,css,close){
	if(!this.Did){this.Did = 'ajax_list';}
	if(!obj){var obj=Object();}
	obj.id=this.Did;
	obj["class"]='acan_win dis_none';
	obj.css={height:'auto',width:'auto'};
	if(css){obj.css=css}
	if(!close){
		obj._close={onclick:'Acan.close(\''+obj.id+'\')','class':'-close'};//关闭按钮
	}
	Acan.base.win(obj,title,html);
	Acan.ajax_bg();
	return jQuery("#"+obj.id+" ._content");
}
//第一次使用需要完善信息
Weibo.user.prototype.wanshan = function(){
	var Did = ".Auth_wanshan";
	var head = "首次使用信息完善"+Weibo.tpl.btnh("返回","Weibo.set.back('"+Did+"')");
	var bhtml = Ahtml.tag('input',{"name":"Y","onchange":"setday('"+this.Did+" ')","style":"margin:0 0 0 5%;width:auto;","size":4,"placeholder":"1990"},'年')
		+Ahtml.tag('select',{"name":"m","onchange":"setday('"+this.Did+" ')"},dateoption("m"))
		+Ahtml.tag('select',{"name":"d","style":"margin-left:5%;"},dateoption("d","",1))+" "
		+Ahtml.tag('select',{"name":"h"},dateoption("h"));
	html = Ahtml.tag("ol",{"class":"Am_list _login _main_bg"},
		Ahtml.tag('li',{},Ahtml.tag("p",{"class":"_t"},"邮 箱:")+Ahtml.tag("p",{"class":"_d"},Ahtml.tag("input",{"type":"text","name":"mail","placeholder":"请输入您的邮箱地址","size":18})))
		+Ahtml.tag('li',{},Ahtml.tag("p",{"class":"_t"},"性 别:")+Ahtml.tag("p",{"class":"_d _check"},
			Weibo.tpl.btn_span("男","Weibo.sex.check('1')",{"class":"_sex","fid":"1"})
			+Weibo.tpl.btn_span("女","Weibo.sex.check('2')",{"class":"_sex","fid":"2"})
		))
		+Ahtml.tag('li',{},Ahtml.tag("p",{"class":"_t"},"生 日:")+Ahtml.tag("p",{"class":"_d _birthday"},bhtml))
		+Ahtml.tag('li',{},Ahtml.tag("p",{"class":"_t"},"地 区:")+Ahtml.tag("p",{"class":"_d"},"<div class=\"_save_area\"></div>"))
		+Ahtml.tag('li',{},Ahtml.tag("p",{"class":"btn"},Weibo.tpl.sub("提交"))
		+Ahtml.tag("p",{"class":"btn"},Weibo.tpl.btn("返回","Weibo.set.back('"+Did+"')")))
	);
	html = Ahtml.tag("form",{"onsubmit":"Weibo.user.wanshan('"+Did+"');return false;","class":"_main -center"},html);
	Weibo.tpl.body(Did,"Auth_wanshan",head,html);
	Weibo.ml(".Wbody",Did);
	var info = Weibo.user.info(Auth.uid);
	if(info.mail){
		jQuery(Did+' input[name="mail"]').val(info.mail);
	}
	if(info.fate.birthday){
		Weibo.check.birthday(".Auth_wanshan",info.fate.birthday);
	}
	var sex = info.fate.sex;
	if(!sex) sex = 1;
	Weibo.sex.check(sex,Did);
	var areaval = {};
	if(info.fate.sheng) areaval[1]=info.fate.sheng;
	if(areaval[1] && info.fate.shi) areaval[2]=info.fate.shi;
	if(areaval[2] && info.fate.xian) areaval[3]=info.fate.xian;
	Asl.wanshan = new Apps.sl(Did+' ._save_area','Asl.wanshan');
	Asl.wanshan.readys({1:{'name':'sheng'},2:{'name':'shi'},3:{'name':'xian'}},Acan.area,areaval);
}

//完善信息提交
Weibo.user.wanshan = function(Did){
	var uobj = jQuery(Did+' input[name="mail"]');
	if(!Acan.regexp.mail.test(uobj.val())){uobj.focus();return;}
	var birthday = Weibo.check.birthday(Did);
	if(!birthday){return;}
	var save={};
	save.user = {"mail":uobj.val()};
	save.fate = {"birthday":birthday,"sex":Weibo.sex.val(),"area":Asl.wanshan.value()};
	var url = Aurl.App+'-api-user_save';
	var data = Weibo.gets(url,save,function(data){
		Acan.alert(data.data.msg,1500);
		Awuser.info()
	});
}
//获取用户信息
Weibo.user.info = function(uid){
	if(!uid){uid=Auth.uid;}
	var info = Acan.storage.get("Auserinfo");
	return info[uid];
}

//登入的用户同步登入远程服务器
Weibo.user.prototype.sync = function(id){
	var url = Aurl.App+'-api-sync';
	var rdata;
	var rdata = Weibo.get(url);
	//第一使用需要完善信息
	try{
	if(rdata.data.user.ready==0){
		this.wanshan();
	}else{
		//jQuery("#weibo_index").attr('src','weibo-index');
		Acan.alert(Acan.base.obj_json(rdata.data),100000);
	}
	}catch(e){}
	if(rdata.status==0){
		setTimeout(this.objname+'.sync()',50000);
	}
}
//用户信息保存
Weibo.user.prototype.save = function(){
	var url = Aurl.App+'-api-user_save';
	var save = obj.serialize();
	var data = Weibo.get(url,save);
	if(data.data.ready==0){
		Acan.alert("完善信息");
	}else{
		Acan.alert(Acan.base.obj_json(data.data),1000);
	}
	if(data.status==0){
		setTimeout(this.objname+'.sync()',5000);
	}
}
//获取用户信息
Weibo.user.prototype.info = function(callback){
	var url = Aurl.App+'-api-userinfo';
	Weibo.gets(url,{},
		function(data){
			if(data.data){
				Acan.storage.save("Auserinfo",data.Auth.uid,data.data);
				if(callback) callback(data.data);
			}
		}
	);
}
//消息
Weibo.chat = function(Did,objname){
	this.Did = Did;
	this.objname = objname;
}
Weibo.chat.prototype = new Weibo.chat();
//消息列表
Weibo.chat.prototype.list = function(){
}
//接受消息先到队列,再处理
Weibo.chat.prototype.recv_queue = function(obj){
	Arqueue[obj.nid] = obj;
}
//接受消息 守护
Weibo.chat.recv_daemon = function(){
	if(Agl.recv_status==false){
		Arqueue={};
	}else{
		if(Acan.count(Arqueue)>0){
			for(var i in Arqueue){
				Achat.recv(Arqueue[i]);
				delete Arqueue[i];
			}
		}
	}
	setTimeout(function() {Weibo.chat.recv_daemon();}, 100);
}
//接受消息
Weibo.chat.prototype.recv = function(obj){
	var status=1,nowchat=jQuery('.weibo_chat').attr('class').indexOf('dis_none');
	var ring_sms = jQuery("#ring_sms");
	ring_sms.attr("autoplay","autoplay");
	ring_sms.attr("src",ring_sms.attr("src"));
	if(jQuery("#nid_"+obj.nid).length>0){return;}
	var chatDid = "c_"+Auth.fid+"_"+obj.fid;
	var html_time = Achat.lasttime(obj.fid,obj.time);
	var html = Ahtml.tag('div',{"class":"_l","id":"nid_"+obj.nid},html_time+
		Ahtml.tag('img',{"class":"avatar","onclick":"Weibo.user.list_one("+obj.fid+",'fate."+Auth.uid+".friend','.weibo_chat')","src":Weibo.avatar(Agl.fid_oid[obj.fid])})+
		Ahtml.tag('div',{"class":"box"},Ahtml.tag('p',{"class":"note"},obj.note))
	);
	var mobj = jQuery('.'+this.Did+' .chat_main #'+chatDid);
	if(mobj.length>0 && nowchat<0){
		status=2;
	}
	mobj.append(html);
	this.toend(mobj.height());
	Achat.data(obj.nid,obj.note,status,2,obj.fid);
	var ubj,friend = Acan.storage.get("fate."+Auth.uid+".friend");
	if(friend[obj.fid]){ubj = friend[obj.fid];}
	Weibo.dialog.save(ubj);
	if(nowchat>0){
		Weibo.dialog();
	}
}
//发送消息
Weibo.chat.prototype.send = function(){
	var tobj = jQuery("."+this.Did+" textarea");
	var note = tobj.val();
	if(note.length<1){tobj.focus();return;}
	var nid = Acan.time('ms');
	var time = Acan.time('s');
	var html_time = Achat.lasttime();
	Achat.queue(nid,note);
	if(note.length==0){return;}
	var html = Ahtml.tag('div',{"class":"_r","id":"nid_"+nid},html_time+
		Ahtml.tag('div',{"class":"box"},Ahtml.tag('p',{"class":"note"},Ahtml.tag('span',{"id":"ss_"+nid,"class":"status sending"},'发送')+note))
		+Ahtml.tag('img',{"class":"avatar","src":Weibo.avatar(Agl.fid_oid[Auth.fid])})
	);
	var mobj = jQuery('.'+this.Did+' .chat_main #'+this.chatDid);
	mobj.append(html);
	tobj.val('');
	this.toend(mobj.height());
	Weibo.dialog.save(this.obj);
}
//聊天框滚动到最后一行
Weibo.chat.prototype.toend = function(height){
	myScroll[this.Did].refresh();
	var slg = height-jQuery('#'+this.Did).height();
	if(slg<0){slg=0;}
	var sobj = jQuery("."+this.Did+" .-scroll");
	sobj.css("-webkit-transform",'translate3d(0px, -'+slg+'px, 0px)');
	if(Acan.browser.opera){
		sobj.css("-o-transform",'translate(0px, -'+slg+'px)');
	}
}
//聊天窗口
Weibo.chat.prototype.show = function(obj,backDid){
	if(backDid.substr(0,1)!='.') backDid='.'+backDid;
	if(!Awauth.check("",backDid)){return;}
	var Did = "weibo_chat";
	var jDid = '.'+Did;
	this.tfid = obj.fid;
	this.toid = obj.oid;
	this.obj = obj;
	jQuery(jDid+" .-nav ._btn_hl").remove();
	jQuery(jDid+" .-nav").text(obj.username);
	jQuery(jDid+" .-nav").append(Weibo.tpl.btnh("返回","Weibo.set.back('"+jDid+"','"+backDid+"')"));
	jQuery(jDid+" .chat_main .chat_note").hide();
	this.chatDid = "c_"+Auth.fid+"_"+this.tfid;
	var main = jQuery(jDid+" .chat_main #"+this.chatDid);
	var add;
	if(main.length>0){
		main.show();
		var data = Acan.storage.get("Achatdata."+Auth.fid);
		for(var nid in data[this.tfid]){
			if(nid=='indexs') continue;
			data[this.tfid][nid].status=2;
		}
		Acan.storage.set("Achatdata."+Auth.fid,data);
		add = 0;
	}else{
		jQuery(jDid+" .chat_main").append(Ahtml.tag("div",{"id":this.chatDid,"class":"chat_note"}));
		add = 1;
	}
	Weibo.ml(backDid,jDid);
	setTimeout(this.objname+".loadhy("+add+")",1);//加载记录
}
Weibo.chat.prototype.ready = function(){
	var jDid = '.'+this.Did;
	if(jQuery(jDid).length==0){
		var head = '',html = '';
		html = Ahtml.tag("div",{"class":"chat_main"});
		Weibo.tpl.body(jDid,this.Did,head,html);
		jQuery(jDid).append(Ahtml.tag('div',{"class":"chat_input"},
			Ahtml.tag('span',{"class":"chat_bottom_smile"},'')+
			Ahtml.tag("textarea",{"name":"note"})+Weibo.tpl.btn("发送","Achat.send()")
		));
	}
}
//加载历史聊天记录
Weibo.chat.prototype.loadhy = function(add){
	var mobj = jQuery('.'+this.Did+' .chat_main #'+this.chatDid);
	if(add!=1){this.toend(mobj.height());return;}
	var iobj = Weibo.user.info();
	var data = Acan.storage.get("Achatdata."+Auth.fid);
	var queue= Achat.queue();
	var html = '',path,avatar,ss='',onclick,otime=0,html_time='';
	var ssop = {'1':{'css':'sending','val':'发送'},'2':{'css':'send','val':'送达'},'3':{'css':'read','val':'已读'}};
	for(var nid in data[this.tfid]){
		html_time = '';
		if(otime==0 || (data[this.tfid][nid].time-otime)>300){
			html_time = Ahtml.tag('div',{'class':"_time _main_bg"},Acan.time("Y-m-d H:i:s",data[this.tfid][nid].time));
		}
		if(nid=='indexs'){continue;}
		var status = data[this.tfid][nid].status;
		if(data[this.tfid][nid].path==1){
			path="_r";avatar=Weibo.avatar(Auth.oid);
			ss=Ahtml.tag('span',{"id":"ss_"+nid,"class":"status "+ssop[status].css},ssop[status].val);
			onclick='';
		}else{
			data[this.tfid][nid].status=2;
			path="_l";avatar=Weibo.avatar(this.toid);
			ss='';
			onclick="Weibo.user.list_one("+this.tfid+",'fate."+Auth.uid+".friend','.weibo_chat')"
		}
		html += Ahtml.tag('div',{"class":path},html_time+
			Ahtml.tag('div',{"class":"box"},Ahtml.tag('p',{"class":"note"},ss+data[this.tfid][nid].note))+Ahtml.tag('img',{"class":"avatar","onclick":onclick,"src":avatar})
		);
		otime = data[this.tfid][nid].time;
	}
	Acan.storage.set("Achatdata."+Auth.fid,data);
	path="_r";avatar=Weibo.avatar(Auth.oid);
	for(var nid in queue){
		html += Ahtml.tag('div',{"class":path+" queue"},
			Ahtml.tag('div',{"class":"box"},Ahtml.tag('p',{"class":"note"},Ahtml.tag('span',{"id":"ss_"+nid,"class":"status "+ssop[1].css},ssop[1].val)+queue[nid].note))+Ahtml.tag('img',{"class":"avatar","src":avatar})
		)
	}
	for(var nid in data){
		if(data[nid].status==1 && data[nid].path==1){
			Achat.queue(nid,data[nid].note,data[nid].time,2);
		}
	}
	mobj.append(html);
	this.toend(mobj.height());
}
//读取,写入聊天记录到发送队列
Weibo.chat.prototype.queue = function(nid,note,time,type){
	if(!time) time = Acan.time();
	if(!type) type=1;
	if(typeof(Acqueue[Auth.fid])!='object'){Acqueue[Auth.fid]={};}
	if(typeof(Acqueue[Auth.fid][this.tfid])!='object'){Acqueue[Auth.fid][this.tfid]={};}
	if(nid>0){
		Acqueue[Auth.fid][this.tfid][nid] = {"time":time,"note":note,"path":"1"};//发送队列
	}
	if(type==1){Achat.data(nid,note,1,1);}
	return Acqueue[Auth.fid][this.tfid];
}
//读取,写入聊天记录到本地
Weibo.chat.prototype.data = function(nid,note,status,path,tfid){
	if(!tfid) tfid=this.tfid;
	if(!status) status=1;//状态1 发送
	if(!path){path=1;}//1是发送信息，2是接受信息
	var data = Acan.storage.get("Achatdata."+Auth.fid);//永久储存
	if(!data){data={};}
	if(typeof(data[tfid])!='object'){data[tfid]={};}
	if(!data[tfid].indexs){data[tfid].indexs={};}
	if(nid>0){
		data[tfid][nid] = {"time":Acan.time(),"note":note,"path":path,"status":status};
		data[tfid].indexs[Acan.count(data[tfid].indexs)] = nid;
		Acan.storage.set("Achatdata."+Auth.fid,data);
	}
	return data[tfid];
}
Weibo.chat.prototype.lasttime = function(tfid,time){
	var otime=0,html_time='',lastnid;
	if(!tfid) tfid=this.tfid;
	if(!time) time = Acan.time();
	var data = Acan.storage.get("Achatdata."+Auth.fid);//永久储存
	if(typeof(data[tfid])=='object' && data[tfid].indexs){
		lastnid = data[tfid].indexs[Acan.count(data[tfid].indexs)-1];
		otime = Math.floor(lastnid/1000);
	}
	if(otime==0 || (time-otime)>120){
		html_time = Ahtml.tag('div',{'class':"_time _main_bg"},Acan.time("Y-m-d H:i:s",time));
	}
	return html_time;
}
Weibo.poll = function(){}
Weibo.poll.ready = function(){
	//用户登入就启动聊天轮询
	if(!Apoll.chat && Awauth.check('chat')==true){
		Weibo.poll.chat();//消息轮询
	}
	setTimeout("Weibo.poll.ready()",1000);
}
Weibo.poll.chat = function(cdata,type){
	if(!type) type=1;
	if(!Awauth.check('chat')){Apoll.chat=false;return;}
	Apoll.chat = 1;
	if(cdata){
		var data = Acan.storage.get("Achatdata."+Auth.fid);//永久储存
		data[cdata.tfid][cdata.nid].status = cdata.status;//变更送达状态
		Acan.storage.set("Achatdata."+Auth.fid,data);//永久储存
		var ssobj = jQuery("#ss_"+cdata.nid);
		if(ssobj.length>0){
			if(cdata.status==2){
				if(ssobj.length>0) ssobj.text("送达");ssobj.attr('class','status send');
			}else if(cdata[i].status==3){
				if(ssobj.length>0) ssobj.text("已读");ssobj.attr('class','status read');
			}
		}
	}
	var time = 100;
	if(Acan.count(Acqueue)>0){
		for(var fid in Acqueue){
			if(Acan.count(Acqueue[fid])>0)
			for(var tfid in Acqueue[fid]){
				if(Acan.count(Acqueue[fid][tfid])>0)
				for(var nid in Acqueue[fid][tfid]){
					var sobj = Acqueue[fid][tfid][nid];
					sobj.fid=fid;sobj.tfid=tfid;sobj.nid=nid;
					Asocket.emit('Achat',sobj);
					delete Acqueue[fid][tfid][nid];
				}
			}
		}
	}
	if(type==1){
		setTimeout(function(){Weibo.poll.chat();},500);
	}
}
Weibo.get = function(url,obj,type){
	if(!obj){obj={};}
	obj.Auth = Auth;
	jQuery("#ajax_bg").removeClass('dis_none');
	var gdate;
	jQuery.ajax({
		async:false,
		type:"POST",url:Weibo.proxy(url),data:obj,
		beforeSend: function(){Acan.ajax.load();},
		ajaxSend: function(){Acan.ajax.load();},
		success: function(data){
			gdate = data;
		}
	});
	setTimeout(function(){Acan.ajax.load(2);},300);
	if(type=="login"){
		return gdate;
	}
	//认证失败删除认证信息重新登入
	if(gdate.Auth.status==0){
		Acan.storage.del("Auth");
		Awauth.check();
	}
	return gdate;
}
//异步请求 fun为回调函数
Weibo.gets = function(url,obj,fun,auth,ab){
	if(!obj){obj={};}
	if(!auth && auth!=0){auth=1;}
	if(!ab){ab = {"bg":1,"load":1};}
	if(!ab.load){ab.load=1;}
	if(!ab.bg){ab.bg=1;}
	if(ab.bg==1) Acan.ajax_bg(1,0);
	if(ab.load==1) Acan.ajax.load();
	var data = {'ajax_id':Agl.ajax_id,'url':url,data:obj};
	Agl.ajax[Agl.ajax_id] = ab;
	Agl.ajax[Agl.ajax_id].callback = fun;
	if(!data.Auth){data.Auth = Auth;}
	Asocket.emit("Aajax",data);
	Agl.ajax_id = Agl.ajax_id+1;
	setTimeout(function() {Acan.ajax_bg(0);}, 5000);
	return;
/*	obj.Auth = Auth;
	jQuery.ajax({
		type:"POST",url:Weibo.proxy(url),data:obj,
		beforeSend: function(){if(ab.load==1) Acan.ajax.load();},
		ajaxSend: function(){if(ab.load==1) Acan.ajax.load();},
		success: function(data){
			if(auth==1){
				//认证失败删除认证信息重新登入
				if(data.Auth.status==0){
					Acan.storage.del("Auth");
					Awauth.check();
				}
			}
			//微博认证失败,登入微博
			try{
				if(data.data.error_code==21301){
					Awauth.show('weibo',"."+ab.backid);
					return;
				}
			}catch(e){}
			if(ab.bg==1) Acan.ajax_bg(0);
			fun(data);//回调函数
			setTimeout(function(){Acan.ajax.load(2);},300);
		},
	});
	return;*/
}
Weibo.getse = function(url,obj,fun,auth,ab){
	if(!obj){obj={};}
	if(!auth && auth!=0){auth=1;}
	obj.Auth = Auth;
	if(!ab){ab.bg=1;ab.load=1;}
	if(ab.bg==1) Acan.ajax_bg(1,0);
	jQuery.ajax({
		type:"POST",url:Weibo.proxy(url),data:obj,
		beforeSend: function(){if(ab.load==1) Acan.ajax.load();},
		ajaxSend: function(){if(ab.load==1) Acan.ajax.load();},
		success: function(data){
			if(auth==1){
				//认证失败删除认证信息重新登入
				if(data.Auth.status==0){
					Acan.storage.del("Auth");
					Awauth.check();
				}
			}
			if(ab.bg==1) Acan.ajax_bg(0);
			fun(data);//回调函数
			setTimeout(function(){Acan.ajax.load(2);},300);
		},
		error: function(){
			//Acan.alert();
			if(ab.bg==1) Acan.ajax_bg(0);
			fun();//回调函数
			setTimeout(function(){Acan.ajax.load(2);},300);
		}
	});
	return;
}
//微博头像获取
Weibo.avatar = function(oid,type){
	if(!Agl.avatar_host || Agl.avatar_host>4) Agl.avatar_host=1;
	if(!type){type='min'};
	if(typeof(oid)=="undefined"){return "/images/button/avatar.gif";}
	var imghost;
	imghost = "http://tp"+Agl.avatar_host+".sinaimg.cn/";
	Agl.avatar_host++;
	if(type=='min'){
		return imghost+oid+"/180/1";
	}else{
		return imghost+oid+"/180/1";
	}
	
}
Weibo.sex = function(){}
//选择配对方式
Weibo.sex.check = function(name,jDid){
	if(!jDid) jDid = "#Auth_wanshan";
	Did = jDid+" ._sex[fid=\""+name+"\"]";
	jQuery(jDid+" ._sex .-icon_rt").remove();
	jQuery(Did).append(Acan.icon.right());
}
//获取配对方式的选项 返回数组
Weibo.sex.val = function(jDid){
	if(!jDid) jDid = "#Auth_wanshan";
	Did = jDid+" ._sex";
	var frr=1;
	jQuery(Did).each(function(i){
		var fid = jQuery(this).attr("fid");
		if(jQuery(this).find(".-icon_rt").length>0){
			frr = fid;
		}
	})
	return frr;
}
Weibo.img_show = function(src){
	Acan.ajax_bg(1,0);
	dsrc = "/images/button/20-0.gif";
	jQuery('.-body').append(Ahtml.tag("div",{"class":"img_show","onclick":"Weibo.img_hide()"},Ahtml.tag("table",{},"<tr><td>"+Ahtml.tag("img",{})+"</td></tr>")));
	Acan.load.img(src,function(){jQuery(".img_show img").attr("src",src)});
}
Weibo.img_hide = function(){
	Acan.ajax_bg(0);
	jQuery('.-body .img_show').remove();
}
Weibo.tpl = function(){}
Weibo.tpl.body = function(Did,id,head,mian){
	var Dbj = jQuery(Did);
	if(Dbj.length==0){jQuery(".-body").append(Ahtml.tag("div",{"class":id+" dis_none"}));Dbj = jQuery(Did);}
	var head = Ahtml.tag("h2",{"class":"-nav"},head);
	var main = Ahtml.tag("div",{"id":id,"class":"-main"},Ahtml.tag("div",{"class":"-scroll"},mian));
	Dbj.html(head+main);
	Dbj.addClass("_page");
	if(id) Weibo.iscroll(id,1);
}
//导航按钮 title:标题 fun:函数 dir:方向
Weibo.tpl.btnh = function(title,fun,dir){
	var obj = {};
	if(!dir){dir="l";}
	if(!obj["class"]) obj["class"] = "_btn _btn_h"+dir;
	else obj["class"] += " _btn _btn_h"+dir;
	if(fun){obj.onclick = fun;}
	return Ahtml.tag("span",obj,title);
}
//按钮 title:标题 fun:函数 dir:方向
Weibo.tpl.btn = function(title,fun,dir){
	if(!dir){dir="l";}
	var obj = {"type":"button","class":"_btn _btn_"+dir,"value":title};
	if(fun){obj.onclick = fun;}
	return Ahtml.tag("input",obj);
}
//按钮 title:标题 fun:函数 dir:方向
Weibo.tpl.btn_span = function(title,fun,obj){
	if(!obj) obj = {};
	if(!obj["class"]) obj["class"] = "_btn";
	else obj["class"] += " _btn";
	if(fun){obj.onclick = fun;}
	return Ahtml.tag("span",obj,title);
}
//提交按钮 title:标题 dir:方向 fun:函数
Weibo.tpl.sub = function(title,fun,dir){
	if(!dir){dir="l";}
	var obj = {"type":"submit","class":"_btn _btn_"+dir,"value":title};
	if(fun){obj.onclick = fun;}
	return Ahtml.tag("input",obj);
}
//向左滑动 显示Did2 隐藏Did1
Weibo.ml = function(Did1,Did2){
	Aback.Did = Did2;//当前页面id
	Aback.bid = Did1;//返回页面id
	var Dbj1 = jQuery(Did1);
	var Dbj2 = jQuery(Did2);
	if(!Acan.base.in_array("dis_none",Dbj2.attr('class').split(' '))) return;//已经是当前页不需要切换
	var hwidth = jQuery("html").width();
	Dbj2.css({"width":hwidth,"left":hwidth});
	Dbj2.removeClass("dis_none");
	Dbj2.show();
	if(Aset.slide.val==1){
		Dbj1.addClass("A_ms A_ml");
		Dbj2.addClass("A_ms A_ml");
	}
	setTimeout('Weibo.ml_call("'+Did1+'","'+Did2+'")',500);
}
Weibo.ml_call = function(Did1,Did2){
	jQuery(Did1).addClass("dis_none");
	jQuery(Did2).removeAttr("style");
	if(Aset.slide.val==1){
		jQuery(Did1).removeClass("A_ms A_ml");
		jQuery(Did2).removeClass("A_ms A_ml");
	}
}
//向右滑动 显示Did1 隐藏Did2
Weibo.mr = function(Did1,Did2){
	if(!Did1 || Did1=='undefined') Did1 = '.Wbody';
	var Dbj1 = jQuery(Did1);
	var Dbj2 = jQuery(Did2);
	if(!Acan.base.in_array("dis_none",Dbj1.attr('class').split(' '))) return;//已经是当前页不需要切换
	var hwidth = jQuery("html").width();
	Dbj1.css({"width":hwidth,"right":hwidth});
	Dbj1.removeClass("dis_none");
	Dbj1.show();
	if(Aset.slide.val==1){
		Dbj2.addClass("A_ms A_mr");
		Dbj1.addClass("A_ms A_mr");
	}
	if(Did1=='.Wbody' && jQuery("#weibo_home").attr('display')!='none'){Weibo.page('home');}
	setTimeout('Weibo.mr_call("'+Did1+'","'+Did2+'")',500);
}
Weibo.mr_call = function(Did1,Did2){
	jQuery(Did2).addClass("dis_none");
	jQuery(Did1).removeAttr("style");
	if(Aset.slide.val==1){
		jQuery(Did1).removeClass("A_ms A_mr");
		jQuery(Did2).removeClass("A_ms A_mr");
	}
}
Weibo.iscroll = function(Did,type){
	setTimeout("Weibo.iscrolls('"+Did+"',"+type+")",200);
}
Weibo.iscrolls = function(Did,type){
	if(!type) type=0;
	if(myScroll[Did] && type==0){
		myScroll[Did].refresh();
	}else{
		myScroll[Did] = new iScroll(Did,{
			useTransform: true,
			useTransition: true,
			onBeforeScrollStart: function (e) {
				var target = e.target;
				while (target.nodeType != 1) target = target.parentNode;
				if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA')
					e.preventDefault();
			}
		});
	}
}
//滚动 fun为下拉一定长度执行函数
Weibo.scroll = function(Did,fun){
	var now;
	var start;
	var Dbj = jQuery(Did);
	var Dht = Dbj.height();
	var tf,tfh;
	Dbj.bind({
		touchstart:function(e){
			tf = Dbj.css("-webkit-transform");
			tf = tf.substring(7,tf.length-1).replace(/ /g,'').split(',');
			start = e.pageY;now = 0;
			Dbj.css("-webkit-transform","translate3d(0px, 0px, 0px)");
			Dbj.bind("touchmove", function(e){
				now = e.pageY - start;
				Dbj.css("-webkit-transform","translate3d(0px, "+now+"px, 0px)");
			});
		},
		touchend:function(e){
			Dbj.unbind("touchmove");
			if(Dht+now>0){
				Weibo.scroll_back(now,Did);//回滚初始位置
			}
			if(now>50 && fun){setTimeout(fun,0);}//下拉一定距离执行 自定义函数
		},
		mousedown:function(e){
			tf = Dbj.css("-webkit-transform");
			tf = tf.substring(7,tf.length-1).replace(/ /g,'').split(',');
			tfh = Acan.base.str_int(tf[tf.length-1]);
			now = 0;
			start = e.pageY;
			Dbj.css("-webkit-transform","translate3d(0px, "+tfh+"px, 0px)");
			Dbj.bind("mousemove", function(e){
				now = e.pageY - start + tfh;
				Dbj.css("-webkit-transform","translate3d(0px, "+now+"px, 0px)");
			});
		},
		mouseup:function(e){
			Dbj.unbind("mousemove");
			if(Dht+now<0 || now >0){
				Weibo.scroll_back(now,Did);//回滚初始位置
			}
			if(now>50 && fun){setTimeout(fun,0);}//下拉一定距离执行 自定义函数
		}
	});
	Dbj.bind();
}
Weibo.scroll_back = function(now,Did){
	alert(1)
	var num,ni;
	var Dbj = jQuery(Did);
	var Dht = Dbj.height();
	var df = Dht+now;
	Acan.alert(df+" "+now)
	if(now<20 && now>0) ni = 1;//顶部向下拉出多余的
	if(df <0 && df > -20) ni = 1;//底部向上拉出多余的
	if(now>0){
		if(ni!=1) ni=Math.floor(now/20);
		num = now-ni;
	}else{
		if(ni!=1) ni=Math.floor(-now/20);
		num = now+ni;
	}
	if(df<-20){
		if(ni!=1) ni=Math.floor(-df/20);
		num = now+ni;
	}
	if(ni==0){
		ni = 1;
	}
	Dbj.css("-webkit-transform","translate3d(0px, "+num+"px, 0px)");
	if(num==0 || df==0){
		return;
	}
	setTimeout("Weibo.scroll_back("+num+",'"+Did+"')",ni);
}

/*
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', loaded, false);
*/
//离线缓存
try{
window.applicationCache.addEventListener('updateready', function(e) {
	if(window.applicationCache.status == window.applicationCache.UPDATEREADY){
		window.applicationCache.swapCache();
		window.location.reload();
		/*
		if (confirm('A new version of this site is available. Load it?')) {
			window.location.reload();
		}*/
	}
}, false);
}catch(e){}



function get_area_val(obj){
	var str = '';
	if(typeof obj != "object"){return str;}
	if(obj.sheng && obj.sheng!=0)
		str = Acan.area[1][obj.sheng];
	if(obj.shi && obj.shi!=0)
		str += ","+Acan.area[2][obj.sheng][obj.shi];
	if(obj.xian && obj.xian!=0)
		str += ","+Acan.area[3][obj.shi][obj.xian];
	return str;
}

function dateoption(type,val,month,year){
	var title = {"Y":"年","m":"月","d":"日","h":"时"};
	var num,html='',str,start,end;
	if(type=="Y"){
		start = 1950;end = 2012;
	}else if(type=="m"){
		start = 1;end = 12;
	}else if(type=="d"){
		start = 1;
		if(Acan.base.in_array(month,['01','03','05','07','08','10','12'])){
			end = 31;
		}else if(month==2){
			if(year%4 == 0){end = 29;}else{end = 28;}
		}else{
			end = 30;
		}
	}else if(type=="h"){
		start = 0;end = 23;
	}
	if(type!="Y"){
		html = Ahtml.tag('option',{"value":""},"&nbsp; &nbsp; "+title[type]);
	}
	for (var i=start; i <= end; i++) {
		if(i<10){str = "0"+i;}else{str = i}
		var obj={"value":str};
		if(val==i){obj.selected = "selected";}
		html += Ahtml.tag('option',obj,str+title[type]);
	};
	return html;
}

function setday(Did){
	if(!Did){Did="";}
	var mobj = jQuery(Did+'._birthday select[name="m"]');
	var yobj = jQuery(Did+'._birthday input[name="Y"]');
	if(yobj.length==0){
		yobj = jQuery(Did+'._birthday select[name="Y"]');
	}
	var year = yobj.val();
	var month = dateoption('d','',mobj.val(),year);
	jQuery(Did+'._birthday select[name="d"]').html(month);
}